package com.example.week9_advanceui;

import android.app.ListActivity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class ListView1_Activity extends ListActivity {

    //定义下拉列表需要显示的文本数组
    private String[] learningSiteArray={"逸夫图书馆","承先图书馆","综合楼","四教","五教","六教"};
    ListView listView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //获取系统默认的Listview组件
        listView=getListView();
        //设置列表视图的数据适配器
        //外观采用系统提供的布局simple_list_item1,数据来自自定义数组
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,learningSiteArray));


      //设置ListView 事件监听
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ListView1_Activity.this,"您选择了" +learningSiteArray[position],Toast.LENGTH_LONG).show();
            }
        }); //若闪退，注意是否在配置清单文件中中注册了Activity
    }

}
